﻿#pragma once

#include <vector>
#include "common.h"
#include "ui/ui.h"
#include "ui/control_base.h"

namespace anip
{
	class Texture2D;

	namespace ui
	{
		class RadioBar;

		class RadioBarItem : public Selectable<RadioBar>
		{
			friend class RadioBar;

		private:
			wstring _text{};
			Texture2D* _tex = nullptr;
			vec2 _texSize;
			bool
				_hovered = false,
				_pressed = false;

			RadioBarItem(RadioBar& parent) : Selectable(parent) {};
			Texture2D* getTex();

		public:
			RadioBarItem(const RadioBarItem& obj) = default;
			~RadioBarItem();

			void setText(const wstring& text);
			wstring getText() { return _text; };
			bool isHovered() const { return _hovered; }

			std::function<void(RadioBarItem& self)>
				onClick;// ,
				//onSelect;
		};

		class RadioBar : public SelectableContainer<Control, RadioBarItem>
		{
		protected:
			void processMouseMove(invec2 pos) override;
			void processMouseLeave() override;
			void processMouseButton(MouseButton btn, ButtonAction action) override;

			int _hoveredIndex = -1;

		public:
			bcolor 
				textColor = r::TextColor,
				normalColor = r::Button_NormalColor,
				selectedColor = r::Button_SelectedColor;

			bfloat 
				pressFactor = r::Button_PressFactor,
				hoverFactor = r::Button_HoverFactor,
				roundRadius = r::RoundRadius;

			RadioBar(Container* parent = nullptr,
				invec2 pos = { 0, 0 }, invec2 size = { 0, 0 });

			RadioBarItem& addItem(const wstring& text);
			int hoveredIndex() const;

			void paint() override;
			void flow(Flow& f) override;
		};
	}
}